package com.guigu.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.guigu.mapper.*;
import com.guigu.pojo.*;
import com.guigu.service.HvipService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
@Service
public class vipServiceImpl implements HvipService {
    @Autowired
    VipMapper vipMapper;
    @Autowired
    UserMapper userMapper;
    @Autowired
    ManagementMapper managementMapper;
    @Autowired
    ConditionnMapper conditionnMapper;
    @Autowired
    MedicalMapper mapper;
    public List<Vip> selectVip(Vip vip) {
        return vipMapper.selectVip(vip);
    }

    public int updatatp(Vip record) {
        return vipMapper.updatatp(record);
    }

    public int  deleteKey(Vip vip) {
        return vipMapper.deleteByPrimaryKey(vip);
    }

    public int updateByPrimaryKeySelec(Vip record) {
        return vipMapper.updateByPrimaryKeySelective(record);
    }

    public int updateByP(Conditionn record) {
        return conditionnMapper.updateByPrimaryKeySelective(record);
    }

    public int updateBy(Medical record) {
        return mapper.updateByPrimaryKeySelective(record);
    }

    public Vip selvid(Integer vid) {
        return vipMapper.selvid(vid);
    }

    public Conditionn seleconid(Integer vid) {
        return conditionnMapper.seleconid(vid);
    }

    public Medical selmeid(Integer vid) {
        return mapper.seleediid(vid);

    }


    public User selectuserKey(User user) {
        return userMapper.selectKey(user);
    }

    public int insertSelecti(User record) {
        return userMapper.insertSelective(record);
    }

    public List<Vip> seleviptme(Vip record) {
        return vipMapper.seleviptm(record);
    }

    public HPagevo<Vip> infovip(HPagevo hPagevo) {
        PageHelper.startPage(hPagevo.getPage(),hPagevo.getNum());
        List<Vip> addpage = vipMapper.addpage(hPagevo.getV());
        PageInfo<Vip> vipPageInfo = new PageInfo<Vip>(addpage);
        long total = vipPageInfo.getTotal();
        HPagevo<Vip> vipHPagevo = new HPagevo<Vip>();
        vipHPagevo.setTotal(total);
        vipHPagevo.setRows(addpage);
        return vipHPagevo;
    }

    public int insertSele(Vip vip) {
        SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd ");
        Date date = new Date(System.currentTimeMillis());
        String format = formatter.format(date);
        vip.setEnrolltime(format);
        return vipMapper.insertSelective(vip);
    }

    public int insertSelectiv(Conditionn record) {

        return conditionnMapper.insert(record);
    }

    public int insertm(Medical record) {
        return mapper.insert(record);
    }


    public List<Management> manuse(Management management) {
        return managementMapper.manuser(management);
    }

    public HPagevo<Management> infovi(HPagevo hPagevo) {
        PageHelper.startPage(hPagevo.getPage(),hPagevo.getNum());
        List<Management> manuserpage = managementMapper.manuserpage(hPagevo.getM());
        PageInfo<Management> managementPageInfo = new PageInfo<Management>(manuserpage);
        long total = managementPageInfo.getTotal();
        HPagevo<Management> managementHPagevo = new HPagevo<Management>();
        managementHPagevo.setTotal(total);
        managementHPagevo.setRows(manuserpage);
        return managementHPagevo;
    }

    public int insertman(Management record) {
        //获取注册账号时间
        SimpleDateFormat formatter= new SimpleDateFormat("yyyy-MM-dd ");
        Date date = new Date(System.currentTimeMillis());
        String format = formatter.format(date);
        record.setCreatetime(format);
        return managementMapper.insertSelective(record);
    }

    public int deleteByyKey(Integer id) {
        return managementMapper.deleteByPrimaryKey(id);
    }

    public int updateByPrimaryKey(Management record) {
        return managementMapper.updateByPrimaryKey(record);
    }

    public Management seid(Integer id) {
        return managementMapper.seleid(id);
    }

    public List<Management> selectjiankangguanlishi() {
        return managementMapper.selectjiankangguanlishi();
    }


}
